package com.whq.thrift.api.web.admin.service.config.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.config.Config;
import com.whq.thrift.api.web.admin.db.config.ConfigMapper;
import com.whq.thrift.api.web.admin.service.config.ConfigService;

@Service
public class ConfigServiceImpl implements ConfigService {
	@Autowired
	private ConfigMapper configMapper;

	public void addRecord(Config record) {
		DataSourceContextHolder.set("dataSourceConfig");
		if(record==null){
			return;
		}
		Date now=new Date();
		record.setUpdate_time(now);
		record.setCreate_time(now);
		this.configMapper.addRecord(record);
	}

	public List<Config> findRecordsByMap(Map<String, Object> whereParams, int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceConfig");
		if(whereParams==null){
			whereParams=new HashMap<String, Object>(0);
		}
		whereParams.put("beginIndex", beginIndex);
		whereParams.put("maxCount", maxCount);
		return this.configMapper.getSelectRecordByMap(whereParams);
	}

	public void updateRecord(Config record) {
		DataSourceContextHolder.set("dataSourceConfig");
		if(record==null){
			return;
		}
		Date now=new Date();
		record.setUpdate_time(now);
		this.configMapper.updRecord(record);
	}

	public void deleteRecord(String id) {
		DataSourceContextHolder.set("dataSourceConfig");
		this.configMapper.delRecord(id);
	}

	public int findRecordCount(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceConfig");
		return this.configMapper.getSelectCountByKey(whereParams);
	}

	public Config findRecordByKey(String id) {
		DataSourceContextHolder.set("dataSourceConfig");
		return this.configMapper.getSelectRecordByKey(id);
	}

}
